#include "StdAfx.h"
#include "NewItemForm.h"
using namespace ItemMgr;
using namespace System;

System::Void NewItemForm::OkButton_Click(System::Object^  sender, System::EventArgs^  e)
{

	//there's got to be a shorter way to write this.
	if (!ItemNameBox->Text->IsNullOrEmpty(ItemNameBox->Text))
	{
		// todo: Move this to ItemInfo stuff once eventually
		ManagedItem^ temp = gcnew ManagedItem;
		// get and set name and description
		temp->setItemName(NewItemForm::ItemNameBox->Text);
		temp->setItemDescription(NewItemForm::ItemDescriptionBox->Text);
		// get and set temp itemflags
		Byte tempFlags = NULL;
		if (RelationshipBox->CheckState == CheckState::Checked)
			tempFlags |= ifRelationship;
		if (PickupBox->CheckState == CheckState::Checked)
			tempFlags |= ifPickup;
		if (InspectBox->CheckState == CheckState::Checked)
			tempFlags |= ifInspect;
		temp->setItemFlags(tempFlags);
		// add temp item to list, then delete it
		m_ItemList->add_Item(temp);
		m_ParentForm->itemNameList->Items->Add(temp->getItemName());
		this->Close();
		delete temp;
	}
	else
		System::Windows::Forms::MessageBox::Show(L"Cannot continue without Item Name", L"Item Needs a name");
}
